package com.wawu;


import com.wawu.handle.AopRequestHandler;
import com.wawu.ioc.ApplicationContext;
import com.wawu.property.AppProperty;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import lombok.Getter;

public class AppInitializer implements ServletContextListener {

    @Getter//能够同个get方法获取
    private static ApplicationContext applicationContext;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // 扫描指定包，初始化上下文
        System.out.println("AppInitializer类所在包:"+this.getClass().getPackage().getName());//输出自己所在的包
        applicationContext = new ApplicationContext(this.getClass().getPackage().getName(), AppProperty.ANNOTATION_PACKAGE);
        AopRequestHandler.initializeRoutes(applicationContext); // 注册路由
        System.out.println("ApplicationContext initialized with components.");
        System.out.println("IOC容器生成，同时能够自动注入");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // 清理资源等操作
        System.out.println("ApplicationContext destroyed.");
    }

}
